package org.jeecg.modules.yc.web.mapper;


import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.jeecg.modules.yc.web.entity.Terminal;

import java.util.List;

/**
 * @Description: 采集器
 * @Author: jeecg-boot
 * @Date:   2023-12-25
 * @Version: V1.0
 */
public interface TerminalMapper extends BaseMapper<Terminal> {

    Terminal selectByDeviceId(@Param("deviceId")String deviceId);

    int updateByDeviceId(@Param("deviceId")String deviceId,@Param("temperature")String temperature,@Param("humidity")String humidity);

    void updateByNo(Terminal terminal);

    @Select("<script>"
            + "SELECT t.id AS terminal_id, t.`name` AS terminal_name, COUNT(s.id) AS sensor_count " +
            "FROM terminal t LEFT JOIN yc_pd_device s ON t.id = s.terminal_id  GROUP BY  t.id"
            + "</script>")
    IPage<Terminal> selectPageVo(Page<Terminal> page, @Param("terminal") Terminal terminal,@Param("sys_org_code")String sys_org_code);


    @Select("<script>SELECT t.sys_org_code FROM `terminal` t GROUP BY sys_org_code;</script>")
    List<String> selectOrgCode();
}
